/**
 * AdminController
 *
 * @description :: Server-side logic for managing admins
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

module.exports = {

  index: function (req, res) {
    console.log(req.session);
    return res.view('admin/index', {layout: 'admin/layout'});
  },

  faq: function (req, res) {
    Faq.find().then(function (record) {
      res.view('admin/faq', {data: record, layout: 'admin/layout'})
    })
  },

  addFaq: function (req, res) {
    var question = req.body.question;
    var answer = req.body.answer;
    var remark = req.body.remark;
    Faq.create({question: question, answer: answer, remark: remark}).then(function (result) {
      console.log(result);
      res.redirect('/admin/faq');
    }).catch(function (err) {
      res.serverError(err);
    })
  },

  deleteFaq: function (req, res) {
    var id = req.params.id;
    Faq.destroy([id]).exec(function (err, record) {
      if (err) return res.serverError(err);
      console.log(record);
      res.redirect('/admin/faq');
    })
  }

};

